package com.geek.water.controller;
import com.geek.water.constant.CodeConstant;
import com.geek.water.entity.Role;
import com.geek.water.service.RoleService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.geek.water.result.Result;
import java.util.List;
import com.geek.water.constant.MessageConstant;

/**
 * @author chenmin
 * @desc TODO
 * @date 2025/7/26
 */
@RestController
@RequestMapping("/admin/role")
@Slf4j
@Api(tags = "后台系统-角色管理接口")
@RequiredArgsConstructor
public class RoleController {

    private final RoleService roleService;

    @GetMapping("list")
    public Result list(){
        List<Role> list = roleService.list();
        if(!CollectionUtils.isEmpty(list)){
           return new Result(CodeConstant.SUCCESS , MessageConstant.GET_ROLE_SUCCESS , list);
        }
        return new Result(CodeConstant.FAIL , MessageConstant.GET_ROLE_FAIL);
    }

    @GetMapping("getRolesByUserId/{id}")
    public Result getRolesByUserId(@PathVariable("id") Long userId){
        List<Long> roleIds = roleService.getRolesByUserId(userId);
        if(!CollectionUtils.isEmpty(roleIds)){
            return new Result(CodeConstant.SUCCESS , MessageConstant.GET_ROLE_SUCCESS , roleIds);
        }
        return new Result(CodeConstant.FAIL , MessageConstant.GET_ROLE_FAIL);
    }

}
